<template>
	<view class="student-follow-container">
		<cc-navbar :title="navbarTitle"></cc-navbar>
		<view class="list">
			<u-steps activeColor="#165dff" dot current="0" direction="column">
				<u-steps-item v-for="(row, index) in list" :key="index">
					<view slot="desc">
						<view class="item-title">
							{{ row.update_time }}
						</view>
						<view class="item-content">
							<view class="item-info">
								<view class="font-info">意向度:</view>
								<view class=""><u-text size="28rpx" :type="row.intentionLevel.type"
										:text="row.intentionLevel.label"></u-text></view>
							</view>
							<view class="item-info">
								<view class="font-info">意向课程:</view>
								<view class="">{{ row.course_name || '-' }}</view>
							</view>
							<view class="item-info">
								<view class="font-info">跟进人:</view>
								<view class="">{{ row.sale_name || '-' }}</view>
							</view>
							<view class="item-info">
								<view class="font-info">跟进方式:</view>
								<view class="">{{ row.followType.label || '-' }}</view>
							</view>
							<view class="item-info">
								<view class="font-info">跟进内容:</view>
								<view class="">{{ row.follow_memo || '-' }}</view>
							</view>
						</view>
					</view>
				</u-steps-item>
			</u-steps>
		</view>
		<cc-loadmore :loading="loading" :current="list.length" :count="count" />
		<cc-empty v-if="!loading && !count" mode="list" />
	</view>
</template>

<script>
	import {
		index as getList
	} from '@/codecat/api/education/intention/follow';
	export default {
		// 学员详情-跟进记录
		name: 'StudentFollow',
		data() {
			return {
				navbarTitle: '',
				loading: false,
				list: [],
				count: 0,
				query: {
					student_id: '',
					page: 1,
					limit: 10
				}
			};
		},
		onLoad() {
			const options = this.$Route.query;
			if (options.id) {
				this.query.student_id = options.id;
				this.getList(1);
			}
		},
		onReachBottom() {
			if (this.list.length < this.count) {
				this.getList();
			}
		},
		methods: {
			getList(first) {
				const query = this.$lodash.cloneDeep(this.query);
				if (first) {
					query.page = 1;
					this.list = [];
					this.count = 0;
				} else {
					query.page += 1;
				}
				this.loading = true;
				getList(query)
					.then((res) => {
						this.loading = false;
						this.query.page = query.page;
						const {
							list,
							count
						} = res.data;
						this.count = count || 0;
						if (Array.isArray(list) && list.length) {
							this.$lodash.forEach(list, (e) => {
								e.visitStatus = this.$getDict('visitStatus', e.status);
								e.intentionLevel = this.$getDict('intentionLevel', e.intention_level);
								e.followType = this.$getDict('followType', e.follow_type);
							});
							this.list = this.list.concat(list);

							if (query.page === 1) {
								this.navbarTitle = `${this.list[0].student_name}-跟进记录`;
							}
						}
					})
					.catch((_) => {
						this.loading = false;
					});
			}
		}
	};
</script>

<style lang="scss" scoped>
	@import './index.scss';
</style>